/* Copyright 2009
 *
 * This program and the accompanying materials
 * are made available under the terms of the
 * Eclipse Public License v1.0 which accompanies
 * this distribution, and is available at
 *
 * 		http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in
 * writing, software distributed under the License is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
 * OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * Contributors:
 * 	   IBM Corporation - initial API and implementation for JDT/DLTK
 *     Sean W. Quinn - initial adoption for use with PHP from various sources.
 */
package org.eclipse.php.internal.ui.preferences.formatter.tab;

import java.net.URL;

import org.eclipse.dltk.ui.formatter.IFormatterModifyDialog;
import org.eclipse.dltk.ui.util.SWTFactory;
import org.eclipse.php.core.formatter.PHPCodeFormatterConstants;
import org.eclipse.php.internal.ui.preferences.formatter.PHPFormatterControlManager;
import org.eclipse.php.internal.ui.preferences.formatter.PHPFormatterMessages;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Text;

/**
 * @author Sean W. Quinn (swquinn@gmail.com)
 */
public class PHPCodeFormatterCommentsTabPage extends PHPCodeFormatterTabPage {

	/**
	 * @param dialog
	 */
	public PHPCodeFormatterCommentsTabPage(final IFormatterModifyDialog dialog) {
		super(dialog);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	@Override
	protected void doCreateOptions(final PHPFormatterControlManager manager, final Composite parent) {
		createGeneralCommentSettingsGroup(manager, parent);
		createPHPDocCommentSettingsGroup(manager, parent);
		createBlockCommentSettingsGroup(manager, parent);
		createLineWidthGroup(manager, parent);
	}

	/*
	 * A helper method to create a number preference for blank lines.
	 */
	private Text createNumberField(final PHPFormatterControlManager manager, final Composite group, final Object key, final String label) {
		final Text textField = manager.createNumber(group, key, label, COLUMN_SPAN);
		return textField;
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createGeneralCommentSettingsGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.CommentsTabPage_group_general_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_JAVADOC_COMMENT,
				PHPFormatterMessages.CommentsTabPage_enable_javadoc_comment_formatting, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_BLOCK_COMMENT,
				PHPFormatterMessages.CommentsTabPage_enable_block_comment_formatting, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_LINE_COMMENT,
				PHPFormatterMessages.CommentsTabPage_enable_line_comment_formatting, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER,
				PHPFormatterMessages.CommentsTabPage_format_header, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_NEVER_INDENT_BLOCK_COMMENTS_ON_FIRST_COLUMN,
				PHPFormatterMessages.CommentsTabPage_never_indent_block_comments_on_first_column, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_NEVER_INDENT_LINE_COMMENTS_ON_FIRST_COLUMN,
				PHPFormatterMessages.CommentsTabPage_never_indent_line_comments_on_first_column, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_JOIN_LINES_IN_COMMENTS,
				PHPFormatterMessages.CommentsTabPage_do_not_join_lines, COLUMN_SPAN);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createPHPDocCommentSettingsGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.CommentsTabPage_group_php_doc_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HTML,
				PHPFormatterMessages.CommentsTabPage_format_html, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_SOURCE,
				PHPFormatterMessages.CommentsTabPage_format_code_snippets, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_COMMENT_INSERT_EMPTY_LINE_BEFORE_ROOT_TAGS,
				PHPFormatterMessages.CommentsTabPage_blank_line_before_javadoc_tags, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_INDENT_ROOT_TAGS,
				PHPFormatterMessages.CommentsTabPage_indent_javadoc_tags, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_INDENT_PARAMETER_DESCRIPTION,
				PHPFormatterMessages.CommentsTabPage_indent_description_after_param, COLUMN_SPAN);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_INSERT_NEW_LINE_FOR_PARAMETER,
				PHPFormatterMessages.CommentsTabPage_new_line_after_param_tags, COLUMN_SPAN);

		// **
		manager.createCheckbox(group,
				PHPCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT,
				PHPFormatterMessages.CommentsTabPage_clear_blank_lines, COLUMN_SPAN);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createBlockCommentSettingsGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.CommentsTabPage_group_block_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		// **
		manager.createCheckbox(group, PHPCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT,
				PHPFormatterMessages.CommentsTabPage_remove_blank_block_comment_lines, COLUMN_SPAN);
	}

	/**
	 * @param manager
	 * @param parent
	 */
	private void createLineWidthGroup(final PHPFormatterControlManager manager, final Composite parent) {
		final Group group = SWTFactory.createGroup(parent, PHPFormatterMessages.CommentsTabPage_group_line_width_title,
				COLUMN_SPAN, 1, GridData.FILL_HORIZONTAL);

		createNumberField(manager, group, PHPCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH,
				PHPFormatterMessages.CommentsTabPage_line_width);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	protected URL getPreviewContent() {
		return getClass().getResource("bracesPreview.php"); //$NON-NLS-1$
	}
}
